﻿namespace Hidistro.UI.Web.Pay
{
    using Hidistro.ControlPanel.Sales;
    using Hidistro.Entities.Orders;
    using Hidistro.Membership.Context;
    using Hishop.Weixin.Pay;
    using Hishop.Weixin.Pay.Domain;
    using Newtonsoft.Json;
    using System;
    using System.Web.UI;

    public class wx_Submit : Page
    {
        public string pay_json = string.Empty;

        protected void Page_Load(object sender, EventArgs e)
        {
            string str = base.Request.QueryString.Get("orderId");
            if (!string.IsNullOrEmpty(str))
            {
                OrderInfo orderInfo = OrderHelper.GetOrderInfo(str);
                if (orderInfo != null)
                {
                    PackageInfo package = new PackageInfo {
                        Body = orderInfo.OrderId,
                        NotifyUrl = string.Format("http://{0}/pay/wx_Pay.aspx", base.Request.Url.Host),
                        OutTradeNo = orderInfo.OrderId,
                        TotalFee = (int) (orderInfo.GetTotal() * 100M)
                    };
                    SiteSettings masterSettings = SettingsManager.GetMasterSettings(false);
                    PayRequestInfo info3 = new PayClient(masterSettings.WeixinAppId, masterSettings.WeixinAppSecret, masterSettings.WeixinPartnerID, masterSettings.WeixinPartnerKey, masterSettings.WeixinPaySignKey).BuildPayRequest(package);
                    this.pay_json = JsonConvert.SerializeObject(info3);
                }
            }
        }
    }
}

